<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../css/templet.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../fonts/font-awesome.min.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../mui/css/mui.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../ali/iconfont.css?01_38" />
		<!--公共js-->
		<script type="text/javascript" src="../common/js/jquery.js?01_38"></script>
		<script type="text/javascript" src="../common/js/fastclick.js?01_38"></script>
		
		<!--插件-->
		<script type="text/javascript" src="../common/js/vue.min.js?01_38"></script>
		<script type="text/javascript" src="../common/js/mui.min.js?01_38"></script>
		
		<script type="text/javascript" src="../common/js/common.js?01_38"></script>
		<script type="text/javascript" src="../common/js/my_common.js?01_38"></script>
		<script type="text/javascript" src="../common/js/main.js?01_38"></script>
		<script type="text/javascript" src="../common/js/app.js?01_38"></script>
		<style>
			#bcid {
				width: 100%;
				position: absolute;
				text-align: center;
				top: 45px;
			}
			
			.tip {
				color: #FFFFFF;
				font-weight: bold;
				text-shadow: 0px -1px #103E5C;
			}
		</style>
	</head>

	<body>
		<header class="bg-red9 fff f-20 pad-t-10 pad-b-10 pad-l-10 pad-r-10" style="top: 0;">
			<div class="pa back" onclick="back();">
				<a></a>
			</div>
			<div class="center" data-l="1261"></div>
		</header>
		<div class="wrap_body bg-000" v-cloak id="app" v-cloak="">
			<div id="bcid">
				<div style="height:40%"></div>
				<p class="tip">...Loding...</p>
			</div>
			<div class="com_title" style="">
				<div class="fiex1">
					<a href="javascript:com_back()"></a>
				</div>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		var app = null;

		function fun1() {
			setlange_obj(); //加载头部语言包
			//截取url中的type值和id值
			var getType = getQueryString("type");
			var getId = getQueryString("id");
			var getScan = getQueryString("scan");
			var scan = null;

			//创建vue
			app = new Vue({
				el: "#app",
				data: {
					getType: getType,
					getId: getId,
					b_lg: global_lange, //语言包
				},

				mounted: function() {
					setTimeout(function() {
						scan = new plus.barcode.Barcode('bcid', '', {
							frameColor: "fd5749",
							scanbarColor: "fd5749",
							background: "000"
						});
						scan.onmarked = onmarked;
						scan.start();
					}, 300)

				},
				methods: {
					gotoart: function(e) { //跳转地址
						clicked(e); //全局
					}
				}
			})

			function onmarked(type, result, file) {
				scan.close();
				result = result.replace(/\n/g, '');

				if(getType == 1) { //核销优惠券
					type1(result);
				} else if(getType == 2) { //绑定店铺
					type2(result); //绑定方法
				} else if(getType == 3) { //点餐

				} else if(getType == 4) { //上下班
					work(result); //上下班扫码方法
				} else if(getType == 5) { //查询会员卡
					type5(result);
				}

				//参数错误重新扫描
				function dataerror(mg) {
					mui.confirm(mg, function(e) {
						if(e.index == 0) {
							scan = new plus.barcode.Barcode('bcid', '', {
								frameColor: "fd5749",
								scanbarColor: "fd5749"
							});
							scan.onmarked = onmarked;
							scan.start();
						}
					})
				}

				//绑定店铺处理
				function type2(table_sn) {
					var table_sn = table_sn;
					if(table_sn) {
						if(isAPP) {
							var preUrl = plus.webview.currentWebview().opener();
							localStorage.setItem("shopSn", table_sn)
							preUrl.evalJS('back_index(2)')
						}
						com_back();
						//						localStorage.setItem("shopSn",table_sn);

					} else {
						dataerror("参数错误~")
					}
				}

				//上下班扫码
				function work(table_sn) {
					if(getScan == 1) {
						if(table_sn) {
							common_ajax(1, {
								uuid: phone_uuid
							}, "put_work_sign_scan", function(res) {
								if(res.status == 1) { //请求成功
									//跳转到扫码页
									//								app.gotoart("../shop/myShop.html?id=2&shop_sn=" + table_sn); //跳转到我的店铺页

									var btnArray2 = [app.b_lg[1008]];
									mui.confirm(app.b_lg[1386], app.b_lg[1050], btnArray2, function(ee) {
										if(ee.index == 0) {
											//确定
											if(isAPP) {
												var ws = plus.webview.currentWebview().opener();
												var preUrl = plus.webview.currentWebview().opener().opener();
												plus.webview.close(ws.id, false)
												preUrl.evalJS('refresh()')
											}
											com_back();
										}
									})

								} else { //请求失败
									mui.toast(res.msg);
								}
							})

						} else {
							dataerror("参数错误~")
						}
					} else {
						if(table_sn) {
							common_ajax(1, {
								uuid: phone_uuid
							}, "put_work_sign_scan", function(res) {
								if(res.status == 1) { //请求成功
									//跳转到扫码页
									//								app.gotoart("../shop/myShop.html?id=2&shop_sn=" + table_sn); //跳转到我的店铺页

									var btnArray2 = [app.b_lg[1008]];
									mui.confirm(app.b_lg[1386], app.b_lg[1050], btnArray2, function(ee) {
										if(ee.index == 0) {
											//确定
											if(isAPP) {
												var preUrl = plus.webview.currentWebview().opener();
												preUrl.evalJS('refresh()')
											}
											com_back();
										}
									})

								} else { //请求失败
									mui.toast(res.msg);
								}
							})

						} else {
							dataerror("参数错误~")
						}
					}

				}

				//核销优惠券
				function type1(coupon_sn) {
					var table_sn = table_sn;
					alert(coupon_sn)
					if(coupon_sn) {
						//						app.gotoart("../coupon/writeOffSuccess.html?id=2&sn="+coupon_sn);//跳转到核销成功页
						common_ajax(1, {
							sn: coupon_sn
						}, "get_coupon_info_bySn", function(res) {
							if(res.status == 1) {
								app.gotoart("../coupon/writeOffSuccess.html?id=2&sn=" + coupon_sn); //跳转到核销成功页
							} else {
								mui.toast(res.msg);
								if(isAPP) {
									var preUrl = plus.webview.currentWebview().opener();
									preUrl.evalJS();
								}
								com_back();
							}
						})
					} else {
						dataerror("参数错误~")
					}
				}

				//查询会员卡
				function type5(coupon_sn) {
					var table_sn = table_sn;
					if(coupon_sn) {
						common_ajax(1, {
							sn: coupon_sn,
							mobile: ""
						}, "get_card_info_by_mobileSn", function(res) {
							if(res.status == 1) {
								app.gotoart("../vip/vipCardInfor.html?id=2&sn=" + coupon_sn); //跳转到核销成功页
							} else {
								mui.toast(res.msg);
								if(isAPP) {
									var preUrl = plus.webview.currentWebview().opener();
									preUrl.evalJS();
								}
								com_back();
							}
						})
					} else {
						dataerror("参数错误~")
					}
				}

			}
		}
	</script>

</html>
